using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace OpenCvTesting
{
	class StethLocationDataManipulator
	{
		private static AbsoluteBodyFeatures absoluteBodyFeatures = new AbsoluteBodyFeatures();

		static StethLocationDataManipulator()
		{
			absoluteBodyFeatures.FillDummyInfo();
		}

		public static PointF GetMappedStethLocation(StethLocationData stethLocationData)
		{
			float scaleX = 1;
			float scaleY = 1;
			if (stethLocationData.LeftCostalMarginPointX - stethLocationData.RightCostalMarginPointX > 0)
			{
				scaleX = (absoluteBodyFeatures.LeftCostalMarginPoint.X - absoluteBodyFeatures.RightCostalMarginPoint.X) / (stethLocationData.LeftCostalMarginPointX - stethLocationData.RightCostalMarginPointX);
			}
			if (stethLocationData.StethLocationY <= stethLocationData.XiphoidProcessPointY)
			{
				if (stethLocationData.XiphoidProcessPointY > 0)
				{
					scaleY = (absoluteBodyFeatures.XiphoidProcessPoint.Y / stethLocationData.XiphoidProcessPointY);
				}
				return new PointF(stethLocationData.StethLocationX * scaleX, stethLocationData.StethLocationY * scaleY);

			}
			else
			{
				if (stethLocationData.RightCostalMarginPointY - stethLocationData.XiphoidProcessPointY > 0)
				{
					scaleY = (absoluteBodyFeatures.RightCostalMarginPoint.Y - absoluteBodyFeatures.XiphoidProcessPoint.Y) / (stethLocationData.RightCostalMarginPointY - stethLocationData.XiphoidProcessPointY);
				}
				return new PointF(stethLocationData.StethLocationX * scaleX, absoluteBodyFeatures.XiphoidProcessPoint.Y + (stethLocationData.StethLocationY - stethLocationData.XiphoidProcessPointY) * scaleY);

			}
			return new PointF(0, 0);
		}
	}
}
